home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / PICTDialog / UDialogs.cp < prev    next >
Encoding:
Text File  |  1995-02-06  |  3.2 KB  |  147 lines  |  [TEXT/MPS ]

  1. // Copyright © 1991 Apple Computer, Inc. All rights reserved.
  2. //    Example of a modal dialog with a PICT inside, with some additional
  3. // TEditText control.
  4. // Kent Sandvik DTS
  5.  
  6. #ifndef __UDIALOGS__
  7. #include "UDialogs.h"
  8. #endif
  9.  
  10. #ifndef __TOOLUTILS__
  11. #include <ToolUtils.h>
  12. #endif
  13.  
  14. #ifndef __FONTS__
  15. #include <Fonts.h>
  16. #endif
  17.  
  18. #ifndef __RESOURCES__
  19. #include <Resources.h>
  20. #endif
  21.  
  22. #ifndef __PACKAGES__
  23. #include <Packages.h>
  24. #endif
  25.  
  26. #ifndef __UMEMORY__
  27. #include <UMemory.h>
  28. #endif
  29.  
  30. #ifndef __USCROLLER__
  31. #include <UScroller.h>
  32. #endif
  33.  
  34. #ifndef __UVIEWSERVER__
  35. #include <UViewServer.h>
  36. #endif
  37.  
  38. #ifndef __UDRAWINGENVIRONMENT__
  39. #include <UDrawingEnvironment.h>
  40. #endif
  41.  
  42. #ifndef __UFAILURE__
  43. #include <UFailure.h>
  44. #endif
  45.  
  46. #ifndef __UGEOMETRY__
  47. #include <UGeometry.h>
  48. #endif
  49.  
  50. #ifndef __UMACAPPUTILITIES__
  51. #include <UMacAppUtilities.h>
  52. #endif
  53.  
  54. #ifndef __MENUS__
  55. #include <Menus.h>
  56. #endif
  57.  
  58. #ifndef __UMENUMGR__
  59. #include <UMenuMgr.h>
  60. #endif
  61.  
  62. #ifndef __OSUTILS__
  63. #include <OSUtils.h>
  64. #endif
  65.  
  66. #ifndef __UWINDOW__
  67. #include <UWindow.h>
  68. #endif
  69.  
  70. #ifndef __UCONTROL__
  71. #include <UControl.h>
  72. #endif
  73.  
  74. #define kSignature                'MOOF'            // qpplication signature
  75. #define kFileType                   'SF01'            // file type code used for document files created by this application
  76.  
  77. const short    kModalID           =    3000;
  78. const short    cName                =    4000;
  79.  
  80. //============================================================================
  81. #undef Inherited
  82. #define Inherited TApplication
  83.  
  84. #pragma segment AInit
  85. DefineClass(TDialogsApplication, TApplication);
  86.  
  87.  void TDialogsApplication::IDialogsApplication()
  88. {
  89.     this->IApplication(kFileType, kSignature);
  90.     
  91.     fLaunchWithNewDocument = false;        // Suppress the creation of a new document at launch
  92.     
  93. }
  94.  
  95.  
  96. //------------------------------------------------------------------------------
  97. #pragma segment ASelCommand
  98.  void  TDialogsApplication::DoMenuCommand(CommandNumber aCommandNumber)        // override
  99.  
  100. {
  101.     switch (aCommandNumber){
  102.     
  103.         case cName:
  104.                 this->ShowModalDialog();        // show dialog box
  105.                 break;            
  106.                 
  107.         default:                                        //    always do this, so other objects get a chance
  108.           Inherited::DoMenuCommand(aCommandNumber);
  109.  
  110.     }
  111. }
  112.  
  113.  
  114. //------------------------------------------------------------------------------
  115. #pragma segment ARes
  116.  void TDialogsApplication::DoSetupMenus()
  117. {
  118.     Inherited::DoSetupMenus();        //    always do this, so other objects get chance
  119.     Enable(cName, true);
  120. }
  121.  
  122.  
  123. //------------------------------------------------------------------------------
  124. #pragma segment ASelCommand
  125.  void TDialogsApplication::ShowModalDialog()
  126. {
  127.     const IDType kDialogView    = 'dlog';    //    dialog view identifier
  128.     const IDType kName            = 'name';    //    edit text identifier
  129.     const IDType kOK                = 'okok';    //    OK button identifier
  130.     const IDType kCancel            = 'cncl';    //    Cancel button identifier
  131.     const IDType kPict            = 'pic1';    // PICT view
  132.     
  133.     TWindow     *aWindow;
  134.     
  135.     FailNIL(aWindow = gViewServer->NewTemplateWindow(kModalID, NULL));
  136.  
  137.     TDialogView *aDialogView = (TDialogView *) aWindow->FindSubView(kDialogView);
  138.     TEditText     *anEditText = (TEditText *) aWindow->FindSubView(kName);
  139.     TPicture     *aPicture = (TPicture *) aWindow->FindSubView(kPict);
  140.     
  141.     IDType dismisser = aWindow->PoseModally();    // show the modal dialog
  142.  
  143.     aWindow->Close();                                        //    dispose of the dialog window
  144. }
  145.  
  146.  
  147.